<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>卡片库存统计</title>

<script type="text/javascript" src="../script/common.js"></script>
<script language="javascript" src="../script/common_stat.js"></script>
<script type="text/javascript" src="../script/pivot.js"></script>
<script type="text/javascript" src="../script/print.js"></script>
<script type="text/javascript" src="../script/crosstab.js"></script>

<script type="text/javascript">
	var crosstab = new Crosstab();
	var statForm;
	var pivot;
	function load(){
		Eui.showNavigation();
		setPages(["queryView","newPivot"]);
		statForm = $("statForm");
		if( Common.cOrg().orgLevel == Constants.ORG_LEVEL_HQ ){
			statForm.orgId.value = null;
		}else{
			statForm.orgId.value = Common.cOrg().id;
		}
		DWR.call("storeQueryService.getCardAreas",function(result){
			Common.initDict(statForm.orgId,result,"全部","id","name");
		})
		$("statForm").orgId.value = Common.cOrg().name
		newPivot();
		CardStore.initCardStoreStat("stat_btn")
	}
	
	function newPivot(){
			var sql = "card_production_stat";
			var crossconf = {};
			crossconf.measures = {"count":"次数","sum":"卡片数量"}
			crossconf.dimensions = {"province":"","cardType":{name:"卡片类型",option:{"baseCardType":"基本卡片类型","name":"卡片类型"}},"cardSpec":{name:"卡片规格",option:{factory:"厂商",name:"卡片规格"}}}
			crossconf.defaultMeasure = {count:true,sum:true};
			crossconf.defaultVertical = {};
			crossconf.defaultHorizon = {province:true,cardType:{baseCardType:true,name:true},"cardSpec":{name:true}};
			pivot = new Pivot('newPivot',sql,null,{
				initPivotHead : initPivotHead
			});
			pivot.initConf(crossconf);
			pivot.setPivotHead('pivotTitle','制卡统计');
	}
	function initPivotHead(div){
		var title = '<table width="100%" border="0" cellspacing="0" cellpadding="5" style="width:600">'
				  + '<tr><td align="center" class="reportTitle" height="50" colspan="3" id="#DIVID#_pivotTitle"></td></tr>'
				  + '<tr><td width="30%">统 计 人：<span id="#DIVID#_statOper"></span></td><td width="35%">统计机构：<span id="#DIVID#_statOrg"></span></td><td>统计时间：<span id="#DIVID#_statTime"></span></td></tr>'
				  + '<tr><td>使用区域：<span id="#DIVID#_orgId"></span></td><td>起始时间：<span id="#DIVID#_beginTime"></span></td><td>结束时间：<span id="#DIVID#_endTime"></span></td></tr>'
				  + '<tr><td>卡片类型：<span id="#DIVID#_cardTypeName"></span></td></tr></table>';
		$(div+'_pivot_head').innerHTML = title.replace(/#DIVID#/g,div);
	}
	function selCardType(){			
		var v = openDialogFrame("/basic/card_type_list.html?",'请选择卡片类型',464,700)
		if (v){
			statForm.cardTypeId.value = v[0];
			statForm.cardTypeName.value = v[1]; 	 
		}
	}
	function doQuery(){ 
		CardStore.formatStatDate()
		if(!checkForm(statForm))return;
		pivot.param = Common.getValues(statForm);
		var orgName = statForm.orgId.value?statForm.orgId.options[statForm.orgId.selectedIndex].text:''
		pivot.setPivotHead('statTime',Format.today(true));
		pivot.setPivotHead('statOper',Common.cOperator().name);
		pivot.setPivotHead('statOrg',Common.cOrg().name);
		pivot.setPivotHead('orgId',pivot.param.orgId?orgName:"全部");
		pivot.setPivotHead('cardTypeName',pivot.param.cardTypeName?pivot.param.cardTypeName:"全部");
		pivot.setPivotHead('beginTime',pivot.param.beginDate);
		pivot.setPivotHead('endTime',pivot.param.endDate);
		pivot.refresh();
		switchPage("newPivot");
	}
	
	function resetStatForm(){
		//statForm.reset();
		//statForm.orgId.value = Common.cOrg().id;
		switchPage('queryView');
	}
</script>
</head>

<body onload="load()">
	<div class="nav"><div id="nav">&nbsp;</div></div>
	<div id="queryView" class="form">
		<div class="formTitle">制卡查询统计：查询条件</div>
		<form id="statForm" name="statForm">
			<input type="hidden" name="cardTypeId"/>
			<input type="hidden" name="orgName"/>
			<table width="100%" cellspacing="0" cellpadding="4" class="col3">
				<tr>
					<td><label>卡片类型</label> <input type="text" name="cardTypeName" ><a class="orga" title="请选择卡片类型" href="javascript:void(0)" onclick="selCardType()">&nbsp;&nbsp;</a></td>
				</tr>
				<tr>
					<td><label>使用区域</label> <select name='orgId'></select></td>
				</tr>
			</table>
			<div id="stat_btn"></div>
		</form>
	</div>
	<!-- Flash 报表-->
	<div id="newPivot" style="display:none;"></div>
</body>

</html>
